<!DOCTYPE html>
<html>
<head>
<title>req_new</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />
 <script type="text/javascript" src="/codebase/dhtmlx.js" /> 

<script>
/*<![CDATA[*/
	var myForm, myForm2,myForm_form_atts;
	var customCss = {
		video_bitrate : "validate_magenta",
		video_codec : "validate_orange"
	};
	function doOnLoad(req_id) {
		var v=document.getElementById("assign_test_id").innerHTML;
		if(v==" "){
			v="";
		}
		if(req_id=="save_success"){
			v="";
		}
		var myEditor_test_guide = new dhtmlXEditor("editorObj");
		var myEditor_req_remark = new dhtmlXEditor("editorObj2");
		
		formStructure=null;
		formStructure=[
						{type:'fieldset',label:'附件',list:[
									{type : 'label', name:'att_label', label:'上传文件最大值: 100 Mb'},
									{type:'upload', name:'myFiles', inputWidth:'600', titleText:'拖拽文件到此区域或点击选择文件上传', url:'/attachment/upload_test_assign', _swfLogs:'enabled',  autoStart:'true', swfPath:'/common/uploader.swf',  swfUrl:'/attachment/upload_test_assign'}
						]},	
		                 
							{type:'block',list:[
									//{type : 'button',name : 'test_new_save_btn',value : '送测'}				
									{type : 'button',name : 'test_assign_save_btn',value : '分配'},
									{type : 'newcolumn'},
									{type : 'button',name : 'test_return_btn',value : '退回'}	
								]
		                  	}	
		                 ];
		//form2
		if (myForm2) {
			myForm2.unload();
			myForm2 = null;

		}
		myForm2 = new dhtmlXForm("form_container2",formStructure);
		//
		if (myForm) {
			myForm.unload();
			myForm = null;

		}
		myForm = new dhtmlXForm("form_container");
		//myForm.loadStruct("/common/testmanager/test_assign.xml");
		myForm.loadStruct("/test/test_assign_form_onload?test_id="+v,function(){
			//var g_test_guide=myForm.getItemValue("test_introduction");
			//var g_req_remark=myForm.getItemValue("test_remark");
			
			//myEditor_req_remark.setContent(g_req_remark);
			//myEditor_test_guide.setContent(g_test_guide);
			if(v!=""){
				myEditor_req_remark.setContentHTML("/test/test_assign_page_remark?test_id="+v);
				myEditor_test_guide.setContentHTML("/test/test_assign_page_guide?test_id="+v);	
			}
			
		});
		
		
		//myForm_form_atts
		if (myForm_form_atts) {
			myForm_form_atts.unload();
			myForm_form_atts = null;
		}
		myForm_form_atts = new dhtmlXForm("form_atts");		
		
		if(v!="")
		{
			myForm_form_atts.loadStruct("/test/test_assign_atts_onload?test_id="+v);
			
			myForm_form_atts.attachEvent("onButtonClick", function(name) {
			
			var btn_tmp=name.split("_");
			if(btn_tmp[0]=="download"){
				//myForm.send("/req/req_assign_detail_page_download_att?att_id="+btn_tmp[1], "get", downloadcallback,true);
				window.location.href = "/req/req_assign_detail_page_download_att?att_id="+btn_tmp[1];
			}
			
			});
			
	
		}
		
		myForm.attachEvent("onButtonClick", function(name) {
			if (name == "add3" || name == "remove3") {
				change_test_executor(name=="add3");
			};	
			
			if(name=="btn_select_req"){
				createWindow();				
			}

		});
		
		myForm2.attachEvent("onButtonClick", function(name) {
		

			if (name == "test_assign_save_btn") {
				var tmp_test_guide=myEditor_test_guide.getContent();
				var get_req_bill_no=myForm.getItemValue("req_bill_no");
				if(get_req_bill_no.length>0){				
					if(tmp_test_guide.length>0){
						var s3=myForm.getSelect("test_executor");
						for (var i=0;i<s3.options.length;i++)
						{
							s3.options[i].selected=true
						}	
						
						myForm.setItemValue("test_introduction", tmp_test_guide);
						
						var tmp_req_remark=myEditor_req_remark.getContent();
						myForm.setItemValue("test_remark", tmp_req_remark);	
						
						var v=document.getElementById("assign_test_id").innerHTML;
						myForm.setItemValue("test_id",v);
						myForm.send("/test/test_assign_save_opt",callback);
						}else{
							alert("【测试指引】 字段为必填项，请录入");
						}
					}
				else{		
					alert("【需求编号】 字段为必填项，请先选择测试项目");
					}
			}
			
			if (name == "test_return_btn") {
				var v=document.getElementById("assign_test_id").innerHTML;
				if(v==""){
					alert("请先进行项目选择");
				}else{
					createWindow_test_return_btn();	
				}
				
			}
			
		});
		
		myForm.attachEvent("onValidateError", function (name, value, result){
			var tmp_label=myForm.getItemLabel(name);	
			if(tmp_label=="测试工作量"){
				alert("【测试工作量】字段，请输入数字,小数位只有一位，且只能为5或0! \n 录入值为"+value);
				myForm.enableItem("assign_btn1");
			}
			else{
				  alert("校验【"+tmp_label+"】 值为【"+value+ "】 ， 请更正");
				  myForm.enableItem("assign_btn1");
			}	   
					
		  
		});
		
		myForm2.attachEvent("onUploadFile", function(realName, serverName) {
			atts_add_gropid(arguments[2].att_gropid);
			atts_add_ids(arguments[2].att_ids);
			//var mu=myForm.getUploader("myFiles");
		});
		
		myForm2.attachEvent("onUploadComplete",function(count){
			//logEvent("<br></br>onUploadComplete "+count+" file"+(count>1?"s were":" was")+" uploaded");
			alert("上传"+count+"个文件完成.");
		});
		
		myForm2.attachEvent("onUploadFail",function(realName){
			//logEvent("onUploadFail, file: "+realName);
			alert("上传文件"+realName+"失败，请检查上传文件大小");
		});
		
		
	}
	
function change_test_executor(block) {
		
		var ida = (block?"test_executor":"test_executor_all");
		var idb = (block?"test_executor_all":"test_executor");
		
		var sa = myForm.getSelect(ida);
		var sb = myForm.getSelect(idb);
		
		var t = myForm.getItemValue(ida);
		if (t.length == 0) return;
		eval("var k={"+t.join(":true,")+":true};");
		
		var w = 0;
		var ind = -1;
		while (w < sa.options.length) {
			if (k[sa.options[w].value]) {
				sb.options.add(new Option(sa.options[w].text,sa.options[w].value));
				sa.options.remove(w);
				ind = w;
			} else {
				w++;
			}
		}
		
		if (sa.options.length > 0 && ind >= 0) {
			if (sa.options.length > 0) sa.options[t.length>1?0:Math.min(ind,sa.options.length-1)].selected = true;
		}
		
	}	
	
function createWindow_test_return_btn() {	
	//alert("open_createWindow");
	
	var p = 0;		
	var id = "return_test_window";
	//
	var w = 700;
	var h = 200;
	var x = 100;
	var y = 300;
	
	//
	dhxWins2=new dhtmlXWindows();
	dhxWins2.createWindow(id, x, y, w, h);
	
	
	//dhxWins2.window(id).center();
	dhxWins2.window(id).setText("测试退回");
	
	dhxWins2.window(id).denyPark();
	dhxWins2.window(id).button("park").hide();
	var v=document.getElementById("assign_test_id").innerHTML;
	
	dhxWins2.window(id).attachURL("/test/test_reject?test_id="+v);

	dhxWins2.attachEvent("onClose", function(win){
	    
	    var ifr = dhxWins2.window(id).getFrame();		    
	    var win_value = ifr.contentWindow.document.getElementById("is_close_parent_window").innerHTML;
	    if(win_value=="true"){
	    	//parent.dhxWins.window("req_assign_window").close();
	    	doOnLoad("save_success");
	    }
	    	
	    return true;
	    
	});
	
	}
	function createWindow() {
		//alert("open_createWindow");
		var p = 0;
		var id = "select_req_window";
		//
		var w = 900;
		var h = 600;
		var x = 50;
		var y = 50;

		//
		dhxWins = new dhtmlXWindows();
		dhxWins.createWindow(id, x, y, w, h);
		dhxWins.window(id).setText("项目选择界面");

		dhxWins.window(id).denyPark();
		dhxWins.window(id).button("park").hide();
		var req_title = myForm.getItemValue("query_req_title");
		var req_bill_no = myForm.getItemValue("query_req_bill_no");
		var technical_director = myForm.getItemValue("query_technical_director");
		var params_tmp = req_title + "," + req_bill_no + ","
				+ technical_director;
		
		  
		dhxWins.window(id).attachURL("/test/test_assign_select_req?params="+params_tmp);
		
		dhxWins.attachEvent("onClose", function(win){
		    
		    var ifr = dhxWins.window(id).getFrame();		    
		    var win_value = ifr.contentWindow.document.getElementById("assign_req_id").innerHTML;
		    //alert("win_value "+win_value);
		    document.getElementById("assign_test_id").innerHTML=win_value;
		   // window.location.pathname="/test/test_assign?req_id="+win_value;
		   // parent.myLayout.cells("a1").attach("/test/test_assign?test_id="+win_value);
		  	doOnLoad();
		    return true;
		    
		});
 	
	}
	
	function atts_add_ids(ids) {
		var txt="";
		//var get_input_att_ids=myForm.getInput("att_id");
		//txt=get_input_att_ids.value;
		txt=myForm.getItemValue("att_id");
		if (txt==""){
			//get_input_att_ids.value=ids;
			myForm.setItemValue("att_id",ids);
		}else{
			//get_input_att_group.value=txt+","+ids;
			myForm.setItemValue("att_id",txt+","+ids);
		}				
		//att_group.hide=true;
		//atts.hidden=true;
	}
	
	function atts_add_gropid(g_id) {
		var txt="";
		//var get_input_att_group=myForm.getInput("att_group_id");
		//txt=get_input_att_group.value;
		txt=myForm.getItemValue("att_group_id");
		if (txt==""){
			//get_input_att_group.value=g_id;
			myForm.setItemValue("att_group_id",g_id);
		}else{
			//get_input_att_group.value=txt+","+g_id;
			myForm.setItemValue("att_group_id",txt+","+g_id);
		}				
		//att_group.hidden=true;
		//atts.hide=true;
	}
	
	var callback=function () {
		//alert("callback");
		
		if(arguments[1]=="true"){
			alert("保存成功");	
			doOnLoad("save_success");
		}
		else{
			alert("保存需求失败，错误信息："+arguments[1]);
		}
	}
	
/* 	function check_workload() {
		var reg = new RegExp("^[0-9]+(.[05]{1})?$");  
	   // var obj = document.getElementById("name");  
	    var check_value=myForm.getItemValue("test_workload");
	    if(!reg.test(check_value)){  
	        alert("【测试工作量】字段，请输入数字,小数位只有一位，且只能为5或0!录入值为"+check_value);  
	        return false;
	    }
	   
	} */
	function check_workload(data) {
		//alert(data);
		//var check_value=myForm.getItemValue("req_workload");
		
		var reg = new RegExp("^[0-9]+(.[05]{1})?$");  
		data=data*1;
		var t_check_value=data.toFixed(1);
			  if(!reg.test(t_check_value)){  
			     //   alert("【需求分析工作量】字段，请输入数字,小数位只有一位，且只能为5或0!录入值为"+check_value);
			        var r=false;
			        return(r);
			    }else{
			    	return(true);
			    }
		}
	/*]]>*/	
</script>
</head>
<body onload="doOnLoad();">
<div id="assign_test_id" name="assign_test_id" th:text="${test_id}" style="display: none;" ></div>
	<table style="padding-left: 50px;">
		<tr>
			<td>
				<div id="form_container" name="form_container"></div>
			</td>
		</tr>
				<tr>
			<td>
				<div id="">测试指引<label style="color:red;">*</label></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="editorObj"  style="width:700px; height:200px; border:1px solid #dfdfdf;"></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="">其他说明</div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="editorObj2" style="width:700px; height:200px;  border:1px solid #dfdfdf;"></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="form_atts" name="form_atts"></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="form_container2" name="form_container2"></div>
			</td>
		</tr>		
	</table>
</body>
</html>